package com.lylg.picture_share.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lylg.picture_share.dao.ImageMapper;
import com.lylg.picture_share.entity.Image;
import com.lylg.picture_share.entity.ImageType;
import com.lylg.picture_share.service.ImageService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ImageServiceImpl implements ImageService {
    @Autowired
    private ImageMapper imageMapper;

    @Override
    public void add(Image image) {
        imageMapper.save(image);


    }

    @Override
    public void passImage(Image image) {
        imageMapper.passImage(image);

    }

    @Override
    public Image getImageById(Integer id) {
        return imageMapper.selectImageById(id);
    }

    @Override
    public PageInfo<Image> getAllImages(Image qb, Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Image> images = imageMapper.selectAllImages(qb);
        PageInfo pageInfo = new PageInfo(images);
        return pageInfo;
    }

    @Override
    public void addPlayCount(Integer image_id) {
       imageMapper.addPlayCount(image_id);
    }

    @Override
    public void addGoodCount(Integer image_id) {
        imageMapper.addGoodCount(image_id);
    }

    @Override
    public List<Image> getMyCollectImages(Integer userId) {
        return imageMapper.selectImagesByUserId(userId);
    }

    @Override
    public List<Image> getMyGoodImages(Integer userId) {
        return imageMapper.selectImagesByUserId2(userId);
    }

    @Override
    public List<Image> getMyUploadImages(Integer userId) {
        return imageMapper.selectImagesByUserId3(userId);
    }

    @Override
    public List<Image> selectImagesByDesc() {
        return imageMapper.selectImagesByDesc();
    }

    @Override
    public PageInfo<Image> getAllImagesFront(Image queryBean, Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Image> images = imageMapper.selectAllImagesFront(queryBean);
        PageInfo pageInfo = new PageInfo(images);
        return pageInfo;
    }

//    @Override
//    public List<Image> selectImagesByName(Image image) {
//        return imageMapper.selectImagesByName(image);
//    }
    public PageInfo<Image> selectImagesByName(Image queryBean,  Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Image> images = imageMapper.selectImagesByName(queryBean);
        PageInfo pageInfo = new PageInfo(images);
        return pageInfo;
    }

}
